//
//  MGRouter.h
//  Express
//
//  Created by lhongl on 2025/9/28.
//  Copyright © 2025 QM. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN

@protocol MGRouterDelegate <NSObject>

@optional
/// 未知url
/// - Parameter url: url
- (void)unFoundRouterForURL:(NSString *)url;

/// 未知传值
/// - Parameter key: key
- (void)unFoundParamaterForKey:(NSString *)key;

/// 重定向
/// - Parameter url: url
- (NSString *)rewriteURL:(NSString *)url;

@end

@interface MGRouter : NSObject

/// 结果代理
@property (nonatomic, weak) id <MGRouterDelegate> delegate;

+ (instancetype)sharedInstance;


/// 注册路由
/// - Parameters:
///   - router: 路由名称
///   - cls: 类
+ (void)addRouter:(NSString *)router forViewController:(Class)cls;


/// 通过url获取类
/// - Parameters:
///   - url: url
///   - userInfo: 传值参数
+ (nullable UIViewController *)viewControllerForURL:(NSString *)url userInfo:(nullable NSDictionary<NSString *, id> *)userInfo;


/// 打开url路由
/// - Parameter url: url
+ (void)openURL:(NSString *)url;


/// 打开路由url
/// - Parameters:
///   - url: url
///   - userInfo: 参数
+ (void)openURL:(NSString *)url userInfo:(nullable NSDictionary<NSString *, id> *)userInfo;


/// 打开路由
/// - Parameters:
///   - url: url
///   - failBlock: 失败
+ (void)openURL:(NSString *)url failure:(void(^ _Nullable)(NSString *url))failBlock;


/// 打开路由
/// - Parameters:
///   - url: url
///   - userInfo: 参数
///   - failBlock: 失败
+ (void)openURL:(NSString *)url userInfo:(nullable NSDictionary<NSString *,id> *)userInfo failure:(void(^ _Nullable)(NSString *url))failBlock;


/// 返回上一页
/// - Parameter animated: 动画
+ (void)goback:(BOOL)animated;


/// 返回指定页
/// - Parameter url: url
+ (void)gobackToURL:(NSString *)url;


/// 返回指定页
/// - Parameters:
///   - url: url
///   - userInfo: 参数
+ (void)gobackToURL:(NSString *)url userInfo:(NSDictionary<NSString *,id> * _Nullable)userInfo;


@end

NS_ASSUME_NONNULL_END
